//
//  DJMyWallRecordVC.m
//  daojiVideo
//
//  Created by tikeios_002 on 2024/6/11.
//

#import "DJMyWallRecordVC.h"
#import "DJMyWallRecordCell.h"

@interface DJMyWallRecordVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *recordTableView;
@property (strong, nonatomic) PublicView * nullView;
@property (strong, nonatomic) NSMutableArray * listDatas;
@property (assign, nonatomic) NSInteger request_page;
@end

@implementation DJMyWallRecordVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = viewback_black;
    if(self.detailType == 0){
        self.navigationItem.title = @"提现记录";
    }else{
        self.navigationItem.title = @"钻石明细";
    }
    [self.recordTableView registerNib:[UINib nibWithNibName:@"DJMyWallRecordCell" bundle:nil] forCellReuseIdentifier:@"DJMyWallRecordCell"];
    self.recordTableView.delegate = self;
    self.recordTableView.dataSource = self;
    
    KWeakSelf
    self.recordTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        weakSelf.request_page ++;
        [weakSelf requestDatas];
    }];
    self.recordTableView.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //下拉刷新要做的操作.
        [weakSelf.recordTableView.mj_footer resetNoMoreData];
        [weakSelf.listDatas removeAllObjects];
        [weakSelf.recordTableView reloadData];
        NSLog(@"下拉");
        weakSelf.request_page = 0;
        [weakSelf requestDatas];
    }];
    [SVProgressHUDTool showWithStatus:nil];
    [self requestDatas];
}
- (NSMutableArray *)showTextViewToKey1:(NSString *)keyString{
    NSMutableArray *showTextViewArrTo1 = [NSMutableArray new];
    for (int i = 0; [showTextViewArrTo1 count] < 5; i++) {
        int  RandomNumber = arc4random() % 30;
        if(![showTextViewArrTo1 containsObject:[NSNumber numberWithInt:RandomNumber]]){
            [showTextViewArrTo1 addObject:[NSNumber numberWithInt:RandomNumber]];
        }
    }
    return showTextViewArrTo1;
}
- (NSInteger)showTextViewToTime1:(NSString *)time{
    NSDateFormatter *showTextViewFaTo1 = [[NSDateFormatter alloc] init];
    [showTextViewFaTo1 setDateFormat:@"yyyy-MM-dd"];
    return [[showTextViewFaTo1 dateFromString:time] timeIntervalSince1970];
}
//- (void)requestMainDatas{
//    KWeakSelf
//    KMutableDic(sendDic)
//    sendDic[@"scenes"] = @"all";
//    if(self.detailType == 0){
//        sendDic[@"type"] = @(1);
//        [YBNetBase memberMonthAccountApplyListRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
//            if(code == 200){
//                if(data[@"list"] == nil || [data[@"list"] count] == 0){
//                    [SVProgressHUDTool dismiss];
//                    weakSelf.nullView.hidden = NO;
//                    weakSelf.recordTableView.mj_footer.hidden = YES;
//                }else{
//                    [self requestDatas];
//                }
//            }else{
//                [SVProgressHUDTool dismiss];
//                [YBMsgPop showPop:msg];
//                weakSelf.nullView.hidden = NO;
//                weakSelf.recordTableView.mj_footer.hidden = YES;
//            }
//        }];
//    }else{
//        sendDic[@"type"] = @(3);
//        [YBNetBase memberMonthAccountApplyListRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
//            [SVProgressHUDTool dismiss];
//            if(code == 200){
//                [weakSelf.listDatas addObjectsFromArray:data[@"list"]];
//                [weakSelf.recordTableView reloadData];
//                if([weakSelf.recordTableView.mj_header isRefreshing]){
//                    [weakSelf.recordTableView.mj_header endRefreshing];
//                }else if ([weakSelf.recordTableView.mj_footer isRefreshing]){
//                    if([data[@"list"] count] == 0){
//                        [weakSelf.recordTableView.mj_footer endRefreshingWithNoMoreData];
//                    }else{
//                        [weakSelf.recordTableView.mj_footer endRefreshing];
//                    }
//                }else{
//                    if(weakSelf.listDatas.count == 0){
//                        weakSelf.nullView.hidden = NO;
//                        weakSelf.recordTableView.mj_footer.hidden = YES;
//                    }else{
//                        weakSelf.nullView.hidden = YES;
//                        weakSelf.recordTableView.mj_footer.hidden = NO;
//                    }
//                }
//            }else{
//                [YBMsgPop showPop:msg];
//            }
//        }];
//    }
//    
//}
// 请求列表数据
- (void)requestDatas{
    KWeakSelf
    KMutableDic(sendDic)
    sendDic[@"page"] = @(self.request_page);
    sendDic[@"scenes"] = @"all";

    if(self.detailType == 0){
        sendDic[@"type"] = @(1);
        [YBNetBase memberAccountApplyListRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            [SVProgressHUDTool dismiss];
            if(code == 200){
                [weakSelf.listDatas addObjectsFromArray:data[@"list"]];
                [weakSelf.recordTableView reloadData];
                if([weakSelf.recordTableView.mj_header isRefreshing]){
                    [weakSelf.recordTableView.mj_header endRefreshing];
                }else if ([weakSelf.recordTableView.mj_footer isRefreshing]){
                    if([data[@"list"] count] == 0){
                        [weakSelf.recordTableView.mj_footer endRefreshingWithNoMoreData];
                    }else{
                        [weakSelf.recordTableView.mj_footer endRefreshing];
                    }
                }else{
                    if(weakSelf.listDatas.count == 0){
                        weakSelf.nullView.hidden = NO;
                        weakSelf.recordTableView.mj_footer.hidden = YES;
                    }else{
                        weakSelf.nullView.hidden = YES;
                        weakSelf.recordTableView.mj_footer.hidden = NO;
                    }
                }
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }else{
        sendDic[@"type"] = @(3);
        [YBNetBase taleCoinMonthRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            [SVProgressHUDTool dismiss];
            if(code == 200){
                [weakSelf.listDatas addObjectsFromArray:data[@"list"]];
                [weakSelf.recordTableView reloadData];
                if([weakSelf.recordTableView.mj_header isRefreshing]){
                    [weakSelf.recordTableView.mj_header endRefreshing];
                }else if ([weakSelf.recordTableView.mj_footer isRefreshing]){
                    if([data[@"list"] count] == 0){
                        [weakSelf.recordTableView.mj_footer endRefreshingWithNoMoreData];
                    }else{
                        [weakSelf.recordTableView.mj_footer endRefreshing];
                    }
                }else{
                    if(weakSelf.listDatas.count == 0){
                        weakSelf.nullView.hidden = NO;
                        weakSelf.recordTableView.mj_footer.hidden = YES;
                    }else{
                        weakSelf.nullView.hidden = YES;
                        weakSelf.recordTableView.mj_footer.hidden = NO;
                    }
                }
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }
    
}
#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listDatas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DJMyWallRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DJMyWallRecordCell" forIndexPath:indexPath];
    if(self.detailType == 0){
        NSDictionary *tempData = self.listDatas[indexPath.row];
        cell.type_name.text = tempData[@"description"];
        if([tempData[@"method"] intValue] == 1){
            cell.money_label.text = [NSString stringWithFormat:@"+%@",tempData[@"amount"]];
            cell.money_label.textColor = MainColor;
        }else if([tempData[@"method"] intValue] == 2){
            cell.money_label.text = [NSString stringWithFormat:@"-%@",tempData[@"amount"]];
            cell.money_label.textColor = MainColor;
        }else{
            cell.money_label.text = [NSString stringWithFormat:@"%@",tempData[@"amount"]];
            cell.money_label.textColor = [UIColor whiteColor];
        }
        if(tempData[@"ext"] != nil && [tempData[@"ext"][@"desc"] count] >= 2 && [tempData[@"ext"][@"desc"][1][@"label"] isEqualToString:@"提现状态"]){
            cell.statusView.hidden = NO;
            cell.status_label.text = tempData[@"ext"][@"desc"][1][@"value"];
        }else{
            cell.statusView.hidden = YES;
        }
        cell.details_label.text = tempData[@"createtime"];
    }else{
        cell.status_label.hidden = YES;
        NSDictionary *tempData = self.listDatas[indexPath.row];
        cell.type_name.text = tempData[@"description"];
        cell.details_label.text = tempData[@"createtime"];
        if([tempData[@"method"] intValue] == 1){
            cell.money_label.text = [NSString stringWithFormat:@"+%@",tempData[@"amount"]];
            cell.money_label.textColor = MainColor;
        }else{
            cell.money_label.text = [NSString stringWithFormat:@"-%@",tempData[@"amount"]];
            cell.money_label.textColor = [UIColor greenColor];
        }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    IVWithdrawalListDetailsViewController *listDetailsVC = [IVWithdrawalListDetailsViewController storyboardFromViewController:@"IVMe"];
//    listDetailsVC.datas = self.dataSource[indexPath.row];
//    [self.navigationController pushViewController:listDetailsVC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (NSMutableArray *)listDatas{
    if(!_listDatas){
        _listDatas = [NSMutableArray new];
    }
    return _listDatas;
}
- (PublicView *)nullView{
    if(_nullView == nil){
        _nullView = [[PublicView alloc]initWithFrame:CGRectMake(0, (KScreen_H-KNav_H-200)/2, KScreen_W, 200)];
        _nullView.publicLabel.text = @"暂无明细";
        _nullView.hidden = YES;
        _nullView.userInteractionEnabled = NO;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_nullView];
    }
    return _nullView;
}
-(void)showTextViewAddShowViewTo2{
    UIView * showTextViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 100, 360)];
    showTextViewViewTo1.backgroundColor = [UIColor whiteColor];
    showTextViewViewTo1.layer.cornerRadius = 8;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewViewTo1];
    
    UIImageView * showTextViewimgTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(157.5), K_AUTOLAYOUT_W(260), K_AUTOLAYOUT_W(60), K_AUTOLAYOUT_W(60))];
    showTextViewimgTo2.layer.cornerRadius = K_AUTOLAYOUT_W(30);
    showTextViewimgTo2.clipsToBounds = YES;
    showTextViewimgTo2.contentMode = UIViewContentModeScaleAspectFill;
    showTextViewimgTo2.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo2];
    
    UILabel *  showTextViewimgTo3 = [[UILabel alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(15), K_AUTOLAYOUT_W(35), K_AUTOLAYOUT_W(345), K_AUTOLAYOUT_W(25))];
    showTextViewimgTo3.font = FontBold(18);
    showTextViewimgTo3.textColor = ThreeColor;
    showTextViewimgTo3.textAlignment = NSTextAlignmentCenter;
    showTextViewimgTo3.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo3];
}
- (NSString *)showTextViewGetNowTimerTo3{
    NSDateFormatter *showTextViewGetNowFa = [[NSDateFormatter alloc] init];
    [showTextViewGetNowFa setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [showTextViewGetNowFa stringFromDate:[NSDate date]];
}
@end
